set more off

use "ssi october 2012", clear

keep if independent == 0

label variable democratXinfo_scale "Dem X knowledge"
label variable republicanXinfo_scale "Rep X knowledge"

replace age = age / 100
gen age2 = age^2
label variable age2 "Age-squared"
local controls democrat info_scale SC BA PG income turnout age female black other 

replace predict_winner = predict_winner * 100
 
*** rescale all X variables to lie between 0 and 1 ***

foreach x in `controls' {

	if regexm("`x'", "i.") {
		local x = subinstr("`x'", "i.", "", 1)
	}
	qui: su `x'
	qui: replace `x' = (`x' - `r(min)') / (`r(max)' - `r(min)')

}


*** do the regression ***


xi: reg predict_winner `controls', robust
keep if e(sample)


eststo clear
eststo: xi: reg predict_winner democrat info_scale democratXinfo_scale, robust
eststo: xi: reg predict_winner `controls' democratXinfo_scale, robust

eststo: xi: reg predict_obama democrat info_scale democratXinfo_scale, robust
eststo: xi: reg predict_obama `controls' democratXinfo_scale, robust

#delimit;
esttab
	using "tableA2.tex"
	,
		replace
		se
		booktabs
		nonum
		mlab("(1)" "(2)" "(3)" "(4)")
		mgroups("Winner prediction" "Voteshare prediction", pattern(1 0 1 0 0 0)
			prefix(\multicolumn{@span}{c}{) suffix(})
			span erepeat(\cmidrule(lr){@span}))
		cells(b(fmt(2)) se(par))
		collabels(none)
		stats(N, label("Observations") fmt(%20.0fc))
		width(\textwidth)
		label
		nogap
		order(democrat info_scale democratXinfo_scale)
		;
#delimit cr

